<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('兑现申请记录列表')" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>会员姓名：</label>
                            <input type="text" name="memberName" placeholder="会员姓名或手机号"/>
                        </li>
                        <li>
                            <label>开户银行：</label>
                            <select name="bankId">
                                <option value="">所有</option>
                                <option class="bankOption" th:each="dict:${@dict.getType('busi_cashdraw_bank')}" th:value="*{dict.dictValue}" th:text="*{dict.dictLabel}"></option>
                            </select>
                        </li>
                        <li>
                            <label>处理状态：</label>
                            <select name="status" style="width: 80px;">
                                <option value="">全部</option>
                                <option value="0">待处理</option>
                                <option value="1">已处理</option>
                                <option value="2">已驳回</option>
                            </select>
                        </li>
                        <li>
                            <label>申请日期： </label>
                            <input type="text" style="width: 120px;" class="time-input" id="startTime" placeholder="开始时间" name="startTime"/>
                        </li>
                        <li>
                            <input type="text" style="width: 120px;" class="time-input" id="endTime" placeholder="结束时间" name="endTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.exportExcel()"><i class="fa fa-download"></i> 导出</a>
                            <a style="color: #000">&nbsp;今日提现申请总金额<span style="color: #F00" th:text="${todayMoney}"></span>&nbsp;今日提现实给总金额<span style="color: #F50" th:text="${todayMoney * 0.95}"></span></a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-primary multiple disabled" onclick="statusAll()" shiro:hasPermission="business:cash:edit">
                <i class="fa fa-edit"></i> 通过申请
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-select-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('business:cash:edit')}]];
    var prefix = ctx + "business/cash";

    //取银行数据
    var bankDict = {};
    $(".bankOption").each(function(){bankDict[$(this).val()] = $(this).text()});
    var accountTypes = ["福豆余额", "个人福豆", "团队福豆", "专项福豆", "福豆田"];

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            exportUrl: prefix + "/export",
            modalName: "兑现申请记录",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '兑现申请ID',
                    visible: false
                },
                {
                    field: 'memberName',
                    title: '申请会员'
                },
                {
                    field: 'accountType',
                    title: '提现类型',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return accountTypes[value];
                    }
                },
                {
                    field: 'drawMoney',
                    title: '申请金额',
                    align: 'center'
                },
                {
                    field: 'drawMoney',
                    title: '税后金额',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return value * 0.95;
                    }
                },
                {
                    field: 'bankId',
                    title: '开户银行',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return bankDict[value];
                    }
                },
                {
                    field: 'bankUser',
                    title: '开户人姓名'
                },
                {
                    field: 'bankCity',
                    title: '开户地'
                },
                {
                    field: 'bankCard',
                    title: '卡号'
                },
                {
                    field: 'status',
                    title: '申请状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                        switch (value){
                            case 0: return "<span style='color:#5c5c5c'>待处理</span>";
                            case 1: return "<span style='color:#db8301'>已处理</span>";
                            case 2: return "<span style='color:#ad3636'>已驳回</span>";
                        }
                    }
                },
                {
                    field: 'createTime',
                    title: '申请时间',
                    align: 'center'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status == 0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="agreeRequest(\'' + row.id + '\')"><i class="fa fa-sign-out"></i>通过申请</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="refuseRequest(\'' + row.id + '\')"><i class="fa fa-trash"></i>驳回申请</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function agreeRequest(id){
        $.modal.confirm("此操作设置该提现申请为已处理完毕, 是否继续?", function() {
            $.operate.post(prefix + "/agree", {
                cashInfoID:id,
                refuse:false
            }, function(response){
                if(response.code == 0){
                    $.modal.alertSuccess('操作成功！')
                }
            });
        });
    }

    function refuseRequest(id){
        $.modal.confirm("此操作设置该提现申请为已驳回状态, 是否继续?", function() {
            $.operate.post(prefix + "/agree", {
                cashInfoID:id,
                refuse:true
            }, function(response){
                if(response.code == 0){
                    $.modal.alertSuccess('操作成功！')
                }
            });
        });
    }

    function cashStatus(id, status){
        $.modal.confirm("确认要修改提现状态吗?", function() {
            $.operate.post(prefix + "/status", {
                cashInfoID:id,
                status:status
            }, function(response){
                if(response.code == 0){
                    $.modal.alertSuccess('操作成功！')
                }
            });
        });
    }

    function statusAll(){
        var ids = $.table.selectColumns("id");
        $.modal.confirm("确认要通过申请吗?", function() {
            $.operate.post(prefix + "/statusAll", {
                ids:ids.join(",")
            }, function(response){
                if(response.code == 0){
                    $.modal.alertSuccess('操作成功！')
                }
            });
        });
    }
</script>
</body>
</html>